| Conditions | 1 |
| Paths | 1 |
| Total Lines | 52 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /* global jest, jasmine, describe, it, expect, beforeEach */ |
||
| 9 | describe('CampaignActions', () => { |
||
| 10 | const middlewares = [thunk]; |
||
| 11 | const mockStore = configureMockStore(middlewares); |
||
| 12 | |||
| 13 | describe('removeCampaignItems()', () => { |
||
| 14 | it('should create 2 actions, request and success, when resolved', () => { |
||
| 15 | const store = mockStore({}); |
||
| 16 | const removeItemApi = () => Promise.resolve(); |
||
| 17 | const expectedActions = [ |
||
| 18 | { |
||
| 19 | type: ACTION_TYPES.REMOVE_CAMPAIGN_ITEM_REQUEST, |
||
| 20 | payload: { campaignId: 1, itemId: 2 }, |
||
| 21 | }, |
||
| 22 | { |
||
| 23 | type: ACTION_TYPES.REMOVE_CAMPAIGN_ITEM_SUCCESS, |
||
| 24 | payload: { campaignId: 1, itemId: 2 }, |
||
| 25 | }, |
||
| 26 | ]; |
||
| 27 | |||
| 28 | return store.dispatch( |
||
| 29 | actions.removeCampaignItem(removeItemApi, 1, 2) |
||
| 30 | ).then(() => { |
||
| 31 | // return of async actions |
||
| 32 | expect(store.getActions()).toEqual(expectedActions); |
||
| 33 | }); |
||
| 34 | }); |
||
| 35 | |||
| 36 | it('should create 2 actions, request and failure, when rejected', () => { |
||
| 37 | const store = mockStore({}); |
||
| 38 | const removeItemApi = () => new Promise((resolve, reject) => { |
||
| 39 | reject(null); |
||
| 40 | }); |
||
| 41 | const expectedActions = [ |
||
| 42 | { |
||
| 43 | type: ACTION_TYPES.REMOVE_CAMPAIGN_ITEM_REQUEST, |
||
| 44 | payload: { campaignId: 1, itemId: 2 }, |
||
| 45 | }, |
||
| 46 | { |
||
| 47 | type: ACTION_TYPES.REMOVE_CAMPAIGN_ITEM_FAILURE, |
||
| 48 | payload: { error: null }, |
||
| 49 | }, |
||
| 50 | ]; |
||
| 51 | |||
| 52 | return store.dispatch( |
||
| 53 | actions.removeCampaignItem(removeItemApi, 1, 2) |
||
| 54 | ).then(() => { |
||
| 55 | // return of async actions |
||
| 56 | expect(store.getActions()).toEqual(expectedActions); |
||
| 57 | }); |
||
| 58 | }); |
||
| 59 | }); |
||
| 60 | }); |
||
| 61 |